<template>
  <div>
    <van-nav-bar title="我的推广" @click-left="onClickLeft" left-arrow />
    <!-- 顶部 -->
    <div class="s-top">
      <!-- 文字 -->
      <div class="top-text">
        <p style="font-size: 32px">
          <span
            style="
              font-family: '思源黑体 CN Bold', '思源黑体 CN';
              font-weight: 700;
            "
            >分享有礼</span
          >
        </p>
        <p style="font-size: 16px">
          <span style="font-family: '思源黑体 CN'; font-weight: 400"
            >奖金可提现</span
          >
        </p>
      </div>
      <!-- 图片 -->
      <div class="top-img" image>
        <img
          id="u8055_img"
          class="img"
          src="https://img0.baidu.com/it/u=142401078,2404165253&fm=253&fmt=auto&app=138&f=JPEG?w=610&h=457"
        />
      </div>
    </div>
    <div class="s-main">
      <div class="goodCalss">
        <span>精选好课</span>
      </div>
      <div class="class-list" :getData="getData">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          <div class="class-box" v-for="(item, index) in list" :key="index" @click="detailClick(item.id)">
            <!-- 课程图片 -->
            <div class="class-img">
              <img :src="item.intro.detail.pic" alt="" />
            </div>
            <!-- 课程文字 -->
            <div class="class-text">
              <div class="text-1">
                <span>{{ item.intro.name }}</span>
              </div>
              <div class="text-2">
                <span>{{ item.sales }}人正在学</span>
              </div>
              <div class="text-3">
                <div class="je">
                  <p class="free" v-if="item.free">免费</p>
                  <p v-else-if="item.discount">
                    <span style="font-weight: 500; color: #ffc71c"
                      >¥{{item.intro.price * item.discount}}&nbsp;</span
                    >
                    <span
                      style="
                        font-weight: 400;
                        color: #cccccc;
                        text-decoration: line-through;
                      "
                      >¥{{item.intro.price}}</span
                    >
                  </p>
                  <p class="discount-price" v-else>￥{{ item.intro.price }}</p>
                </div>
                <div class="btn">
                  <span>赚¥13.5</span>
                </div>
              </div>
            </div>
          </div>
        </van-list>
      </div>
    </div>
  </div>
</template>

<script>
import { get } from "@/utils/http.js";
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    async getData() {
      return await get("/session/goodSession");
    },
    onClickLeft() {
      this.$router.back();
    },
    async onLoad() {
      let data = await this.getData();
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求

      for (let i = 0; i < 2; i++) {
        this.list.push(...data);
      }
      // 加载状态结束
      this.loading = false;

      // 数据全部加载完成
      if (this.list.length >= 10) {
        this.finished = true;
      }
    },
    /**
     * 跳转到对应详情页面
     */
    detailClick(id){
      this.$router.push("/detail/" + id);
    }
  },
};
</script>


<style lang="scss" scoped>
.van-nav-bar {
  height: 54px;
  line-height: 54px;
}
.s-top {
  width: 375px;
  height: 170px;
  background: inherit;
  // background-color: rgba(255, 199, 28, 1);
  background-color: #f8c476;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .top-text {
    width: 129px;
    height: 96px;
    color: white;
    margin-left: 15px;
    p {
      margin: 0px 0px 10px 10px;
    }
  }
  .top-img {
    width: 220px;
    height: 170px;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
.s-main {
  width: 375px;
  background-color: white;
  .goodCalss {
    width: 375px;
    height: 60px;
    line-height: 60px;
    span {
      font-size: 18px;
      font-weight: 500;
      margin-left: 15px;
    }
  }
  .class-list {
    width: 100%;
    .class-box {
      width: 336px;
      height: 88px;
      margin: 0 auto;
      margin-bottom: 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .class-img {
        width: 124px;
        height: 81px;
        border-radius: 10px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 10px;
        }
      }
      .class-text {
        width: 192px;
        height: 81px;
        .text-1 {
          width: 182px;
          font-weight: 500;
          font-size: 13px;
        }
        .text-2 {
          margin-top: 3px;
          font-size: 12px;
          color: #999999;
        }
        .text-3 {
          width: 192px;
          height: 30px;
          font-size: 15px;
          margin-top: 3px;
          display: flex;
          justify-content: space-between;
          p {
            margin: 0;
          }
          .btn {
            width: 70px;
            height: 20px;
            text-align: center;
            border: 1px solid #ff6262;
            border-radius: 50px;
            span {
              font-weight: 500;
              font-style: normal;
              font-size: 12px;
              color: #ff6262;
              line-height: 20px;
            }
          }
        }
      }
    }
  }
}
</style>